#! /bin/bash
HIVE_HOME=/usr/bin/hive


if [[ $1 == '' ]];
then dt=`date -d '-1 day' "+%Y-%m-%d"`
else dt=$1
fi


${HIVE_HOME} -S -e "


SET hive.exec.dynamic.partition=true;
SET hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions.pernode=10000;
set hive.exec.max.dynamic.partitions=100000;
set hive.exec.max.created.files=150000;
--hive压缩
set hive.exec.compress.intermediate=true;
set hive.exec.compress.output=true;
--写入时压缩生效
set hive.exec.orc.compression.strategy=COMPRESSION;


insert overwrite table zx_dwd.dwd_dim_calendar
select
       id,
       datelist
from zx_ods.ods_calendar;


insert into table zx_dwd.dwd_dim_class_studying_student_count partition (dt)
select id,
       school_id,
       subject_id,
       class_id,
       studying_student_count,
       studying_date,
       dt
from zx_ods.ods_class_studying_student_count
where studying_date = '${dt}';

insert into table zx_dwd.dwd_dim_course_table_upload_detail partition (dt)
select id,
       base_id,
       class_id,
       class_date,
       content,
       teacher_id,
       teacher_name,
       job_number,
       classroom_id,
       classroom_name,
       is_outline,
       class_mode,
       is_stage_exam,
       is_pay,
       tutor_teacher_id,
       tutor_teacher_name,
       tutor_job_number,
       is_subsidy,
       answer_teacher_id,
       answer_teacher_name,
       answer_job_number,
       remark,
       create_time,
       dt
from zx_ods.ods_course_table_upload_detail
where class_date = '${dt}';


insert into table zx_dwd.dwd_fact_student_leave_apply partition (dt)
select id,
       class_id,
       student_id,
       audit_state,
       audit_person,
       audit_time,
       audit_remark,
       leave_type,
       leave_reason,
       substr(begin_time,1,19) as begin_time,
       begin_time_type,
       substr(end_time,1,19) as end_time,
       end_time_type,
       days,
       cancel_state,
       cancel_time,
       old_leave_id,
       leave_remark,
       valid_state,
       create_time,
       dt
from zx_ods.ods_student_leave_apply
where substr(begin_time,1,10) = '${dt}';

insert overwrite table zx_dwd.dwd_dim_tbh_class_time_table
select id,
       class_id,
       morning_template_id,
       morning_begin_time,
       morning_end_time,
       afternoon_template_id,
       afternoon_begin_time,
       afternoon_end_time,
       evening_template_id,
       evening_begin_time,
       evening_end_time,
       use_begin_date,
       use_end_date,
       create_time,
       create_person,
       remark
from zx_ods.ods_tbh_class_time_table;

insert into table zx_dwd.dwd_fact_tbh_student_signin_record partition (dt)
select id,
       normal_class_flag,
       time_table_id,
       class_id,
       student_id,
       substr(signin_time,1,19) as signin_time,
       signin_date,
       inner_flag,
       signin_type,
       share_state,
       inner_ip,
       dt
from zx_ods.ods_tbh_student_signin_record
where signin_date = '${dt}';

